<?php
if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3, 
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Function:    sugar-iphone-client for SugarCRM
* Description: Index file
* Author:      Editha Kuske - 2008, Richard John Jensen 2009
* Revision:      $Id: iphone.php 6 2009-12-26 16:59:05Z richardjohnjensen $
********************************************************************************/

set_include_path(dirname(__FILE__) . '/..' . PATH_SEPARATOR . get_include_path()); //patch

include("sugar-iphone-client/header.php");
require_once('sugar-iphone-client/detail_masks.php');

if (isset($_SESSION['authenticated_user_id']) && ($_SESSION['authenticated_user_id'] > ' ')) {
    if (isset($ar_bean_descr)) {
        $str_head = ": ".$ar_bean_descr['module_name'];
    }
    switch ($modus) {
    case 'list':
        $_SESSION['bean_id'] = "0";
        
        header_line($bean, $modus);
        $data_list_par = "bean=$bean&amp;modus=detail";
        include("sugar-iphone-client/show_list.php");
        break;
        
    case 'detail':
        if (isset($_POST['btn_create']) || isset($_POST['btn_update'])) {
            $sugar_soap_client->getMetaData($ar_bean_descr);
            if (execute_submit($bean_id, $ar_bean_descr)) {
                $last_pos = count($_SESSION['location'])-1;
                unset($_SESSION['location'][$last_pos]);
                unset($GLOBALS['_POST']);
                if ($bean_id) {
                    header("Location: iphone.php?bean=$bean&modus=detail&bean_id=$bean_id");
                }
            }
        } else if (isset($_GET['action'])) {
            if ($_GET['action'] == select) {
                $sel_par = $_GET['sel_par'];
                $related_bean = $_GET['related_bean'];
                $mod1 = $ar_beans[$bean]['module_name'];
                $mod2 = $ar_beans[$related_bean]['module_name'];
                if ((($bean == 'Call')|| ($bean == 'Meeting')) && ($related_bean = 'Contact')) {
                    // calls_contacts, meetings_contacts
                    $sugar_soap_client->set_relationship($mod2, $sel_par, $mod1, $bean_id);
                } else {
                    $sugar_soap_client->set_relationship($mod1, $bean_id, $mod2, $sel_par);
                }
            }
            $sugar_soap_client->getModuleData($bean_id);
        } else if ($bean_id != "0") {
            $sugar_soap_client->getModuleData($bean_id);
        }
        $name = "";
        if (isset($ar_meta_fields['name']['value'])) {
            $name = $ar_meta_fields['name']['value'];
        }
        
        header_line($bean, $modus, $name);
        if (!isset($GLOBALS['_GET']['scroll']) && !isset($GLOBALS['_POST']['search'])) {
            $_SESSION['only_my_items'] = 1;
            $_SESSION['start_pos'] = 0;
        }
        //print_r($ar_meta_fields);
        include("sugar-iphone-client/show_detail.php");
        break;
        
    case 'related':
        include("sugar-iphone-client/show_related.php");
        break;
        
    case 'copyright':
        header_line($bean, $modus);
        include("sugar-iphone-client/copyright.php");
        break;
        
        default:
        $_SESSION['only_my_items'] = 1;
        $_SESSION['start_pos'] = 0;
        
        header_line($bean, $modus);
        $tr_odd[0] = 'class="tr-odd"';
        $tr_odd[1] = "";
        $i = 0;
        foreach($ar_beans as $key => $val) {
            if ($val['main_menu'] == 'visible') {
			$html = <<<__BLOCK__
			<tr><td colspan="2" "$tr_odd[$i]"><a href="iphone.php?bean=$key&amp;modus=list">$val[module_name]</a><br /></td></tr>
__BLOCK__;
			echo $html;

                $i = ($i + 1)%2;
            }
        }
        
        //Calendar View  <tr><td colspan="2" $tr_odd><a href="iphone.php?bean=Calendar&modus=list">Calender View</a><br /></td></tr>
        
        break;
    }
} else {
    if (!empty($GLOBALS['_GET'])) {
        header("Location: iphone.php");
    } else if (!empty($GLOBALS['_SESSION'])) {
        unset($GLOBALS['_SESSION']);
    }
    
    login_form($user_name, $user_password, $login_failed);
}
include("sugar-iphone-client/footer.php");
?>